package com.lhd.thread;

import com.lhd.bean.Colinfo;
import com.lhd.tool.Tool2;
import lombok.extern.slf4j.Slf4j;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

/**
 * 具体的业务操作
 */
@Slf4j
public class MyPrint {


		
	private static final List<Colinfo> clist = Colinfo.getColinfo("WAA_ACT_IND_T");

	public void print(String fileName) {

		try (BufferedWriter bwriter = new BufferedWriter(new FileWriter(fileName, true))) {
			// 如果文件已存在则在后面追加

			for (int i = 0; i <= 100; i++) {
				String temp = Thread.currentThread().getName() + ": " + i + "--------------我是一条华丽的小尾巴#";
				//log.info(temp);
				bwriter.write(temp);
				bwriter.newLine();
				bwriter.flush();
			}


		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void print2(String fileName,int ti) {

		try (FileWriter fwriter = new FileWriter(fileName, true)) {
			// 如果文件已存在则在后面追加

			for (int i = 1; i <= 100; i = i + 1) {
				String line = Tool2.GenRowByRule(clist, ti) + "\n";
				String line2 = Thread.currentThread().getName() + ": " + i + "--------------我是一条华丽的小尾巴@" + "\n";
				log.info(line2);
				fwriter.write(line);
				if (i % 100 == 0) {
					fwriter.flush();
				}
			}


		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			log.info("fwriter closed");
		}

	}
}
